package com.zh.web.openApi;

import com.zh.common.exception.BusinessException;
import com.zh.web.base.ApiResult;
import com.zh.web.config.DefaultFeignConfig;
import com.zh.web.domain.media.vo.ArticleVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDateTime;
import java.util.List;

@FeignClient(name = "ls-service-media", path = "/article", configuration = DefaultFeignConfig.class, contextId = "articleClient", fallback = ArticleClientFallback.class)
public interface ArticleClient {

    @GetMapping("/praise/count")
    ApiResult<Integer> getArticlePraise(@RequestParam("id") Long id);

    @PostMapping("/list")
    ApiResult<List<ArticleVo>> listArticle(@RequestBody List<Long> ids);

    @GetMapping("/list/after")
    ApiResult<List<ArticleVo>> listArticleAfterTime(@RequestParam("time") LocalDateTime time);
}

class ArticleClientFallback implements ArticleClient {


    @Override
    public ApiResult<Integer> getArticlePraise(Long id) {
        throw new BusinessException("系统繁忙,请稍后再试");
    }

    @Override
    public ApiResult<List<ArticleVo>> listArticle(List<Long> ids) {
        throw new BusinessException("系统繁忙,请稍后再试");
    }

    @Override
    public ApiResult<List<ArticleVo>> listArticleAfterTime(LocalDateTime time) {
        throw new BusinessException("系统繁忙,请稍后再试");
    }
}
